#define _GNU_SOURCE
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

static pthread_t p1 = 0;
static pthread_t p2 = 0;
static pthread_t p3 = 0;
/*
	无初始值
	1 .data         00000000  0000000000000000  0000000000000000  000002d1  2**0
				  CONTENTS, ALLOC, LOAD, DATA
	2 .bss          00100020  0000000000000000  0000000000000000  000002e0  2**5
				  ALLOC
	有初始值
	1 .data         00100000  0000000000000000  0000000000000000  000002e0  2**5
				  CONTENTS, ALLOC, LOAD, DATA
	2 .bss          00000018  0000000000000000  0000000000000000  001002e0  2**3
				  ALLOC
*/
static char buffer[1024 * 1024];

void *f1(void *pv) {
	sleep(1);
	return "test";
}
void *f2(void *pv) {
	char *r = NULL;
	pthread_join(p1, (void **)&r);
	printf("线程2获得返回值 %s\n", r);
	return NULL;
}
void *f3(void *pv) {
	char *r = NULL;
	pthread_join(p1, (void **)&r);
	printf("线程2获得返回值 %s\n", r);
	return NULL;
}
int main(void) {
	assert(pthread_create(&p1, NULL, f1, NULL) == 0);
	assert(pthread_create(&p2, NULL, f2, NULL) == 0);
	assert(pthread_create(&p3, NULL, f3, NULL) == 0);
	char *r = NULL;
	pthread_join(p2, (void **)&r);
	pthread_join(p3, (void **)&r);
	pthread_join(p1, (void **)&r);
	// pthread_yield();
	printf("主线程获得返回值 %s\n", r);
	return 0;
}